package servlet;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import pojo.CurriCulum;
import service.LogicService;

import org.apache.commons.lang.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Array;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 2022.03.17测试完成 由吴俊莹编写完成
 * 用户增加课程表
 */
@WebServlet(name = "/InserServlet", value = "/InserServlet")
public class InserServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=UTF-8");

        CurriCulum curriCulum = new CurriCulum();
        LogicService logic = new LogicService();
        String x = null;
        try {
            String sele = req.getParameter("seles");
            JSONArray jsonArray = JSONArray.parseArray(sele);
            x = logic.InsertKe(jsonArray, logic.teacherID(jsonArray.parseObject(jsonArray.get(0).toString()).getString("name")));


        } catch (SQLException e) {
            e.printStackTrace();
        }

        PrintWriter out = resp.getWriter();
        out.print(x);


    }
}
